﻿using AiXiu.BLL;
using AiXiu.Common;
using AiXiu.IBLL;
using AiXiu.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AiXiu.WebStite
{
	public partial class AvatarEdit1 : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{

		}
		/// <summary>
		/// 给头像做保存
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
        protected void btnAvatar_Click(object sender, EventArgs e)
        {
			//读取信息
			TBUsers users = IdentityManager.ReadUser();
			users.Avatar = hfAvatar.Value;
			//更新资料
			IUserManger profileManager = new UserManger();
			OperResult<TBUsers> editResult = profileManager.EditAvatar(users);
            if (editResult.StatusCode == StatusCode.Succeed)
            {
				TBUsers userEneiey = editResult.ReadResult();
				//读取缓存用户信息
				TBUsers userCookie = IdentityManager.ReadUser();
                if (userCookie == null)
                {
					this.Alert("Cookienull", "缓存读取出错");
                }
				userCookie.Avatar = userEneiey.Avatar;
				//更新缓存用户信息
				IdentityManager.SaveUser(userCookie);
				//跳转到个人页面
				Response.Redirect("Personal.aspx");
            }
            else
            {
				this.Alert("editerror", editResult.Message);
            }

		}
    }
}